package com.springboot2.shiro.web.controller;

import com.springboot2.shiro.auth.bind.annotation.LoginAccount;
import com.springboot2.shiro.comm.entity.RespResult;
import com.springboot2.shiro.data.enity.User;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.apache.shiro.authz.annotation.RequiresUser;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * AuthController
 *
 * @author Archx[archx@foxmail.com]
 * at 2018/7/13 22:29
 */
@RestController
public class AuthController {

    @GetMapping("/auth")
    @RequiresUser
    public RespResult index(@LoginAccount User user) {
        return RespResult.builder().result(user).build();
    }

    @GetMapping("/unauth")
    public RespResult unauth() {
        RespResult.Builder builder = RespResult.builder();
        return builder.code(RespResult.Code.Failure).message("操作未授权").build();
    }

    @RequestMapping("/ok")
    @RequiresPermissions("system:*")
    public RespResult ok(@LoginAccount User user) {
        return RespResult.builder().result(user).build();
    }
}
